package com.example.teesystem.entityDto;

import com.example.teesystem.common.utils.FileUtil;
import com.example.teesystem.entity.Exam;
import com.example.teesystem.entity.ExamIssue;
import com.example.teesystem.entity.Issue;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : NieYaShi
 * @version : v1.0
 * @createTime : 2022/4/21 16:30
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MarkedIssueMessage {
    private Integer issueId;
    private String question;
    private String selectionA;
    private String selectionB;
    private String selectionC;
    private String selectionD;
    private List<String> urlList = new ArrayList<>();
    private Integer type;
    private Integer issueScore;
    private String issueAnswer;
    private Integer studentScore;
    private String studentAnswer;
    private String issueMessage;

    public MarkedIssueMessage(Issue issue, Exam exam, ExamIssue examIssue){
        BeanUtils.copyProperties(issue, this);
        this.issueId = issue.getId();
        this.issueAnswer = issue.getAnswer();
        this.issueScore = examIssue.getScore();
        this.studentScore = exam.getScore();
        this.studentAnswer = exam.getAnswer();
        this.issueMessage = exam.getMessage();

        String url = issue.getUrl().trim();
        if (!url.equals("")){
            String[] urls = url.split("\\$");
            for (String fileUrl : urls){
                urlList.add(FileUtil.FILE_PREFIX + fileUrl);
            }
        }
    }
}
